<template>
  <div class="outing">
    <div class="module-title">外出情况</div>
    <div class="outing-content">
      <div class="total-count">
        <span class="label">外出总人数：</span>
        <span class="value">{{ totalCount }}</span>
      </div>
      <div class="list-container">
        <div class="list-header">
          <div class="header-cell">组别</div>
          <div class="header-cell">人数</div>
        </div>
        <div class="list-body">
          <div v-if="loading" class="loading">
            <div class="loading-spinner"></div>
            <p>加载中...</p>
          </div>
          <div v-else-if="outingList.length === 0" class="no-data">
            暂无外出数据
          </div>
          <div v-else v-for="(item, index) in outingList" :key="index" class="list-row">
            <div class="list-cell">{{ item.groupName }}</div>
            <div class="list-cell">{{ item.groupCount }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Outing',
  data() {
    return {
      totalCount: 0,
      outingList: [],
      loading: true
    };
  },
  created() {
    this.loadOutingData();
  },
  methods: {
    async loadOutingData() {
      this.loading = true;
      try {
        const response = await this.$displayapi.getOutCount();
        if (response && response.code === "200" && response.data) {
          this.totalCount = response.data.countStudent || 0;
          this.outingList = response.data.outDTOList || [];
        } else {
          this.totalCount = 0;
          this.outingList = [];
        }
      } catch (error) {
        console.error('获取外出数据失败:', error);
        this.totalCount = 0;
        this.outingList = [];
      } finally {
        this.loading = false;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.outing {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;

  .module-title {
    font-size: 18px;
    color: #68d8fe;
    margin-bottom: 15px;
    font-weight: bold;
  }

  .outing-content {
    flex: 1;
    display: flex;
    flex-direction: column;

    .total-count {
      margin-bottom: 15px;
      padding: 10px;
      background-color: rgba(104, 216, 254, 0.1);
      border-radius: 4px;
      border: 1px solid rgba(104, 216, 254, 0.3);

      .label {
        color: #68d8fe;
        margin-right: 10px;
      }

      .value {
        color: #d3d6dd;
        font-weight: bold;
      }
    }

    .list-container {
      flex: 1;
      display: flex;
      flex-direction: column;
      overflow: hidden;

      .list-header {
        display: flex;
        background-color: rgba(104, 216, 254, 0.1);
        border-bottom: 1px solid rgba(104, 216, 254, 0.5);

        .header-cell {
          flex: 1;
          padding: 10px;
          text-align: center;
          color: #68d8fe;
          font-weight: bold;
        }
      }

      .list-body {
        flex: 1;
        overflow-y: auto;
        max-height: 200px;

        &::-webkit-scrollbar {
          width: 5px;
        }

        &::-webkit-scrollbar-track {
          background: rgba(19, 25, 47, 0.5);
        }

        &::-webkit-scrollbar-thumb {
          background-color: rgba(104, 216, 254, 0.5);
          border-radius: 3px;
        }

        .loading {
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          height: 200px;

          .loading-spinner {
            width: 40px;
            height: 40px;
            border: 3px solid rgba(104, 216, 254, 0.3);
            border-radius: 50%;
            border-top-color: #68d8fe;
            animation: spin 1s linear infinite;
            margin-bottom: 10px;
          }

          p {
            color: #d3d6dd;
          }

          @keyframes spin {
            to { transform: rotate(360deg); }
          }
        }

        .no-data {
          text-align: center;
          padding: 20px;
          color: #909399;
          font-style: italic;
        }

        .list-row {
          display: flex;
          border-bottom: 1px solid rgba(104, 216, 254, 0.1);

          &:hover {
            background-color: rgba(104, 216, 254, 0.05);
          }

          .list-cell {
            flex: 1;
            padding: 10px;
            text-align: center;
            color: #d3d6dd;
          }
        }
      }
    }
  }
}
</style> 